package com.gate.ws.spring.service.impl;

import com.gate.ws.spring.request.RpcConfig;
import com.gate.ws.spring.service.MqSender;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.apache.rocketmq.spring.support.RocketMQHeaders;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class RocketMqServiceImpl implements MqSender {

    private final RocketMQTemplate rocketMqTemplate;

    @Value("nami.mqTags")
    private String mqTags;

    @Override
    public boolean send(String topic, String msg) {
        return this.send(topic, mqTags, msg);
    }

    @Override
    public boolean send(String topic, String tags, String body) {
        // 发送带tag的消息
        Message<String> message = MessageBuilder.withPayload(body).setHeader(RocketMQHeaders.TAGS, tags).build();
        rocketMqTemplate.send(topic, message);
        return true;
    }
}
